#include "core/main.h"

namespace mike
{

static std::map< std::string, std::string > sConsole;

void RenderString( unsigned int x, unsigned int y, const std::string& text )
{
    int viewport[ 4 ];

    glGetIntegerv( GL_VIEWPORT, viewport );

    glMatrixMode( GL_PROJECTION );

    glPushMatrix();
    glLoadIdentity();

    gluOrtho2D( 0, viewport[ 2 ], 0, viewport[ 3 ] );

    glMatrixMode( GL_MODELVIEW );

    glPushMatrix();
    glLoadIdentity();

    glRasterPos2i( x, y );

    //( GL_DEPTH_TEST );

    for ( auto it = text.begin(), end = text.end(); it != end; ++it)
    {
        glutBitmapCharacter( GLUT_BITMAP_9_BY_15, *it );
    }

    //glEnable( GL_DEPTH_TEST );

    glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
}

void GlTextConsolePrint( const std::string& channel, const std::string& string )
{
    sConsole[ channel ] = string;
}

void GlTextConsoleRender()
{
    unsigned int currentX = 10, currentY = 10;

    for( auto it = sConsole.begin(); it != sConsole.end(); ++it)
    {
        std::string channel = it->first;
        std::string string  = it->second;

        RenderString( currentX, currentY, channel + ": " + string );

        currentY = currentY + 20;
    }
}

};